{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "8dd62a5c",
   "metadata": {
    "tags": []
   },
   "source": [
    "# YFinance Tutorial: Pulling Free Financial Data\n",
    "\n",
    "yfinance is a popular Python library that offers a reliable, fast, and easy way to fetch historical market data from Yahoo Finance. Whether you're a seasoned data analyst, a budding quant trader, or a finance enthusiast, yfinance is a tool you'll find indispensable. In this tutorial, we'll walk through the basics of using yfinance to pull financial data.\n",
    "\n",
    "## Documentation\n",
    "You can find the online documentation for `yfinance` here: https://python-yahoofinance.readthedocs.io/en/latest/\n",
    "\n",
    "## Setting Up\n",
    "\n",
    "Ensure you have `yfinance` installed. If not, install it using pip, inside a notebook cell:\n",
    "\n",
    "```python\n",
    "!pip install yfinance\n",
    "```\n",
    "\n",
    "* If you are installing from the terminal, use: `pip install yfinance`.\n",
    "* If you followed the getting_started instructions, your python environment will already have it installed.\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d5934d62-2119-47a3-bbe7-d30c2a4e7fe0",
   "metadata": {},
   "source": [
    "---\n",
    "## Basic Usage of yfinance\n",
    "### Importing the library\n",
    "\n",
    "After installation, you can import yfinance in your Python script or notebook:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "c7f1133c",
   "metadata": {},
   "outputs": [],
   "source": [
    "import yfinance as yf"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d2d49a91",
   "metadata": {},
   "source": [
    "### Getting Historical Data\n",
    "\n",
    "To fetch historical market data for a specific stock, use the yf.Ticker class. For example, let's fetch data for Apple Inc:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a5f41eb4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "yfinance.Ticker object <AAPL>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "apple = yf.Ticker(\"AAPL\")\n",
    "apple"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "caa4203b-0708-4572-bc6d-b249a24cbad4",
   "metadata": {},
   "source": [
    "* You can get the historical market data using the history method. By default, it retrieves the last five days of stock data.\n",
    "* We will now reference the object `apple` when extracting data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "ea924e73",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2023-12-22 00:00:00-05:00</th>\n",
       "      <td>195.179993</td>\n",
       "      <td>195.410004</td>\n",
       "      <td>192.970001</td>\n",
       "      <td>193.600006</td>\n",
       "      <td>37122800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-26 00:00:00-05:00</th>\n",
       "      <td>193.610001</td>\n",
       "      <td>193.889999</td>\n",
       "      <td>192.830002</td>\n",
       "      <td>193.050003</td>\n",
       "      <td>28919300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-27 00:00:00-05:00</th>\n",
       "      <td>192.490005</td>\n",
       "      <td>193.500000</td>\n",
       "      <td>191.089996</td>\n",
       "      <td>193.149994</td>\n",
       "      <td>48087700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-28 00:00:00-05:00</th>\n",
       "      <td>194.139999</td>\n",
       "      <td>194.660004</td>\n",
       "      <td>193.169998</td>\n",
       "      <td>193.580002</td>\n",
       "      <td>34049900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-29 00:00:00-05:00</th>\n",
       "      <td>193.899994</td>\n",
       "      <td>194.399994</td>\n",
       "      <td>191.729996</td>\n",
       "      <td>192.529999</td>\n",
       "      <td>42628800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Open        High         Low       Close  \\\n",
       "Date                                                                        \n",
       "2023-12-22 00:00:00-05:00  195.179993  195.410004  192.970001  193.600006   \n",
       "2023-12-26 00:00:00-05:00  193.610001  193.889999  192.830002  193.050003   \n",
       "2023-12-27 00:00:00-05:00  192.490005  193.500000  191.089996  193.149994   \n",
       "2023-12-28 00:00:00-05:00  194.139999  194.660004  193.169998  193.580002   \n",
       "2023-12-29 00:00:00-05:00  193.899994  194.399994  191.729996  192.529999   \n",
       "\n",
       "                             Volume  Dividends  Stock Splits  \n",
       "Date                                                          \n",
       "2023-12-22 00:00:00-05:00  37122800        0.0           0.0  \n",
       "2023-12-26 00:00:00-05:00  28919300        0.0           0.0  \n",
       "2023-12-27 00:00:00-05:00  48087700        0.0           0.0  \n",
       "2023-12-28 00:00:00-05:00  34049900        0.0           0.0  \n",
       "2023-12-29 00:00:00-05:00  42628800        0.0           0.0  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Get the last 5 days of historical data\n",
    "hist = apple.history(period=\"5d\")\n",
    "hist\n",
    "\n",
    "# Fetching Real-Time Data\n",
    "# Note: Real-time data might be delayed due to limitations from Yahoo Finance"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "807f4f50-fbbc-46d4-8d10-bab1c730ee56",
   "metadata": {},
   "source": [
    "* To fetch data for a specific period, you can specify the period or start and end dates:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "e5949d9a-dc8b-440e-b859-ca1bdab67fca",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "History: Monthly\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2023-12-22 00:00:00-05:00</th>\n",
       "      <td>195.179993</td>\n",
       "      <td>195.410004</td>\n",
       "      <td>192.970001</td>\n",
       "      <td>193.600006</td>\n",
       "      <td>37122800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-26 00:00:00-05:00</th>\n",
       "      <td>193.610001</td>\n",
       "      <td>193.889999</td>\n",
       "      <td>192.830002</td>\n",
       "      <td>193.050003</td>\n",
       "      <td>28919300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-27 00:00:00-05:00</th>\n",
       "      <td>192.490005</td>\n",
       "      <td>193.500000</td>\n",
       "      <td>191.089996</td>\n",
       "      <td>193.149994</td>\n",
       "      <td>48087700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-28 00:00:00-05:00</th>\n",
       "      <td>194.139999</td>\n",
       "      <td>194.660004</td>\n",
       "      <td>193.169998</td>\n",
       "      <td>193.580002</td>\n",
       "      <td>34049900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-29 00:00:00-05:00</th>\n",
       "      <td>193.899994</td>\n",
       "      <td>194.399994</td>\n",
       "      <td>191.729996</td>\n",
       "      <td>192.529999</td>\n",
       "      <td>42628800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Open        High         Low       Close  \\\n",
       "Date                                                                        \n",
       "2023-12-22 00:00:00-05:00  195.179993  195.410004  192.970001  193.600006   \n",
       "2023-12-26 00:00:00-05:00  193.610001  193.889999  192.830002  193.050003   \n",
       "2023-12-27 00:00:00-05:00  192.490005  193.500000  191.089996  193.149994   \n",
       "2023-12-28 00:00:00-05:00  194.139999  194.660004  193.169998  193.580002   \n",
       "2023-12-29 00:00:00-05:00  193.899994  194.399994  191.729996  192.529999   \n",
       "\n",
       "                             Volume  Dividends  Stock Splits  \n",
       "Date                                                          \n",
       "2023-12-22 00:00:00-05:00  37122800        0.0           0.0  \n",
       "2023-12-26 00:00:00-05:00  28919300        0.0           0.0  \n",
       "2023-12-27 00:00:00-05:00  48087700        0.0           0.0  \n",
       "2023-12-28 00:00:00-05:00  34049900        0.0           0.0  \n",
       "2023-12-29 00:00:00-05:00  42628800        0.0           0.0  "
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Data for a specific period\n",
    "hist_1m = apple.history(period=\"1mo\")  # 1 month\n",
    "hist_1year = apple.history(start=\"2020-01-01\", end=\"2021-01-01\")  # Specific date range, for each day\n",
    "\n",
    "print('History: Monthly')\n",
    "hist_1m.tail()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "3d29e836-6a06-4454-adcc-58369ec8d4a4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "History: Year - each day\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2020-01-02 00:00:00-05:00</th>\n",
       "      <td>72.151629</td>\n",
       "      <td>73.213546</td>\n",
       "      <td>71.895896</td>\n",
       "      <td>73.152657</td>\n",
       "      <td>135480400</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-03 00:00:00-05:00</th>\n",
       "      <td>72.373271</td>\n",
       "      <td>73.208674</td>\n",
       "      <td>72.214960</td>\n",
       "      <td>72.441467</td>\n",
       "      <td>146322800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-06 00:00:00-05:00</th>\n",
       "      <td>71.554898</td>\n",
       "      <td>73.057647</td>\n",
       "      <td>71.301596</td>\n",
       "      <td>73.018677</td>\n",
       "      <td>118387200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-07 00:00:00-05:00</th>\n",
       "      <td>73.028425</td>\n",
       "      <td>73.286596</td>\n",
       "      <td>72.453631</td>\n",
       "      <td>72.675270</td>\n",
       "      <td>108872000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-08 00:00:00-05:00</th>\n",
       "      <td>72.375691</td>\n",
       "      <td>74.148793</td>\n",
       "      <td>72.375691</td>\n",
       "      <td>73.844345</td>\n",
       "      <td>132079200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-12-24 00:00:00-05:00</th>\n",
       "      <td>129.041004</td>\n",
       "      <td>131.143865</td>\n",
       "      <td>128.824821</td>\n",
       "      <td>129.679718</td>\n",
       "      <td>54930100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-12-28 00:00:00-05:00</th>\n",
       "      <td>131.664685</td>\n",
       "      <td>134.956539</td>\n",
       "      <td>131.193005</td>\n",
       "      <td>134.317825</td>\n",
       "      <td>124486200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-12-29 00:00:00-05:00</th>\n",
       "      <td>135.654209</td>\n",
       "      <td>136.381357</td>\n",
       "      <td>132.008588</td>\n",
       "      <td>132.529388</td>\n",
       "      <td>121047300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-12-30 00:00:00-05:00</th>\n",
       "      <td>133.227090</td>\n",
       "      <td>133.629978</td>\n",
       "      <td>131.084915</td>\n",
       "      <td>131.399368</td>\n",
       "      <td>96452100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-12-31 00:00:00-05:00</th>\n",
       "      <td>131.753114</td>\n",
       "      <td>132.401664</td>\n",
       "      <td>129.434070</td>\n",
       "      <td>130.387238</td>\n",
       "      <td>99116600</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>253 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Open        High         Low       Close  \\\n",
       "Date                                                                        \n",
       "2020-01-02 00:00:00-05:00   72.151629   73.213546   71.895896   73.152657   \n",
       "2020-01-03 00:00:00-05:00   72.373271   73.208674   72.214960   72.441467   \n",
       "2020-01-06 00:00:00-05:00   71.554898   73.057647   71.301596   73.018677   \n",
       "2020-01-07 00:00:00-05:00   73.028425   73.286596   72.453631   72.675270   \n",
       "2020-01-08 00:00:00-05:00   72.375691   74.148793   72.375691   73.844345   \n",
       "...                               ...         ...         ...         ...   \n",
       "2020-12-24 00:00:00-05:00  129.041004  131.143865  128.824821  129.679718   \n",
       "2020-12-28 00:00:00-05:00  131.664685  134.956539  131.193005  134.317825   \n",
       "2020-12-29 00:00:00-05:00  135.654209  136.381357  132.008588  132.529388   \n",
       "2020-12-30 00:00:00-05:00  133.227090  133.629978  131.084915  131.399368   \n",
       "2020-12-31 00:00:00-05:00  131.753114  132.401664  129.434070  130.387238   \n",
       "\n",
       "                              Volume  Dividends  Stock Splits  \n",
       "Date                                                           \n",
       "2020-01-02 00:00:00-05:00  135480400        0.0           0.0  \n",
       "2020-01-03 00:00:00-05:00  146322800        0.0           0.0  \n",
       "2020-01-06 00:00:00-05:00  118387200        0.0           0.0  \n",
       "2020-01-07 00:00:00-05:00  108872000        0.0           0.0  \n",
       "2020-01-08 00:00:00-05:00  132079200        0.0           0.0  \n",
       "...                              ...        ...           ...  \n",
       "2020-12-24 00:00:00-05:00   54930100        0.0           0.0  \n",
       "2020-12-28 00:00:00-05:00  124486200        0.0           0.0  \n",
       "2020-12-29 00:00:00-05:00  121047300        0.0           0.0  \n",
       "2020-12-30 00:00:00-05:00   96452100        0.0           0.0  \n",
       "2020-12-31 00:00:00-05:00   99116600        0.0           0.0  \n",
       "\n",
       "[253 rows x 7 columns]"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "print('History: Year - each day')\n",
    "hist_1year"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "569cae53-9b49-445d-8dcc-cd3d48a7047c",
   "metadata": {},
   "source": [
    "### Adjusting for Stock Splits\n",
    "yfinance automatically adjusts historical data for stock splits. If you prefer unadjusted data, set auto_adjust to False:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "73972225-3e9c-4f8a-80a1-75f226fce0a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Adj Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2023-11-30 00:00:00-05:00</th>\n",
       "      <td>189.839996</td>\n",
       "      <td>190.320007</td>\n",
       "      <td>188.190002</td>\n",
       "      <td>189.949997</td>\n",
       "      <td>189.949997</td>\n",
       "      <td>48794400</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-01 00:00:00-05:00</th>\n",
       "      <td>190.330002</td>\n",
       "      <td>191.559998</td>\n",
       "      <td>189.229996</td>\n",
       "      <td>191.240005</td>\n",
       "      <td>191.240005</td>\n",
       "      <td>45679300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-04 00:00:00-05:00</th>\n",
       "      <td>189.979996</td>\n",
       "      <td>190.050003</td>\n",
       "      <td>187.449997</td>\n",
       "      <td>189.429993</td>\n",
       "      <td>189.429993</td>\n",
       "      <td>43389500</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-05 00:00:00-05:00</th>\n",
       "      <td>190.210007</td>\n",
       "      <td>194.399994</td>\n",
       "      <td>190.179993</td>\n",
       "      <td>193.419998</td>\n",
       "      <td>193.419998</td>\n",
       "      <td>66628400</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-06 00:00:00-05:00</th>\n",
       "      <td>194.449997</td>\n",
       "      <td>194.759995</td>\n",
       "      <td>192.110001</td>\n",
       "      <td>192.320007</td>\n",
       "      <td>192.320007</td>\n",
       "      <td>41089700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-07 00:00:00-05:00</th>\n",
       "      <td>193.630005</td>\n",
       "      <td>195.000000</td>\n",
       "      <td>193.589996</td>\n",
       "      <td>194.270004</td>\n",
       "      <td>194.270004</td>\n",
       "      <td>47477700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-08 00:00:00-05:00</th>\n",
       "      <td>194.199997</td>\n",
       "      <td>195.990005</td>\n",
       "      <td>193.669998</td>\n",
       "      <td>195.710007</td>\n",
       "      <td>195.710007</td>\n",
       "      <td>53377300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-11 00:00:00-05:00</th>\n",
       "      <td>193.110001</td>\n",
       "      <td>193.490005</td>\n",
       "      <td>191.419998</td>\n",
       "      <td>193.179993</td>\n",
       "      <td>193.179993</td>\n",
       "      <td>60943700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-12 00:00:00-05:00</th>\n",
       "      <td>193.080002</td>\n",
       "      <td>194.720001</td>\n",
       "      <td>191.720001</td>\n",
       "      <td>194.710007</td>\n",
       "      <td>194.710007</td>\n",
       "      <td>52696900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-13 00:00:00-05:00</th>\n",
       "      <td>195.089996</td>\n",
       "      <td>198.000000</td>\n",
       "      <td>194.850006</td>\n",
       "      <td>197.960007</td>\n",
       "      <td>197.960007</td>\n",
       "      <td>70404200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-14 00:00:00-05:00</th>\n",
       "      <td>198.020004</td>\n",
       "      <td>199.619995</td>\n",
       "      <td>196.160004</td>\n",
       "      <td>198.110001</td>\n",
       "      <td>198.110001</td>\n",
       "      <td>66831600</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-15 00:00:00-05:00</th>\n",
       "      <td>197.529999</td>\n",
       "      <td>198.399994</td>\n",
       "      <td>197.000000</td>\n",
       "      <td>197.570007</td>\n",
       "      <td>197.570007</td>\n",
       "      <td>128256700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-18 00:00:00-05:00</th>\n",
       "      <td>196.089996</td>\n",
       "      <td>196.630005</td>\n",
       "      <td>194.389999</td>\n",
       "      <td>195.889999</td>\n",
       "      <td>195.889999</td>\n",
       "      <td>55751900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-19 00:00:00-05:00</th>\n",
       "      <td>196.160004</td>\n",
       "      <td>196.949997</td>\n",
       "      <td>195.889999</td>\n",
       "      <td>196.940002</td>\n",
       "      <td>196.940002</td>\n",
       "      <td>40714100</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-20 00:00:00-05:00</th>\n",
       "      <td>196.899994</td>\n",
       "      <td>197.679993</td>\n",
       "      <td>194.830002</td>\n",
       "      <td>194.830002</td>\n",
       "      <td>194.830002</td>\n",
       "      <td>52242800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-21 00:00:00-05:00</th>\n",
       "      <td>196.100006</td>\n",
       "      <td>197.080002</td>\n",
       "      <td>193.500000</td>\n",
       "      <td>194.679993</td>\n",
       "      <td>194.679993</td>\n",
       "      <td>46482500</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-22 00:00:00-05:00</th>\n",
       "      <td>195.179993</td>\n",
       "      <td>195.410004</td>\n",
       "      <td>192.970001</td>\n",
       "      <td>193.600006</td>\n",
       "      <td>193.600006</td>\n",
       "      <td>37122800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-26 00:00:00-05:00</th>\n",
       "      <td>193.610001</td>\n",
       "      <td>193.889999</td>\n",
       "      <td>192.830002</td>\n",
       "      <td>193.050003</td>\n",
       "      <td>193.050003</td>\n",
       "      <td>28919300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-27 00:00:00-05:00</th>\n",
       "      <td>192.490005</td>\n",
       "      <td>193.500000</td>\n",
       "      <td>191.089996</td>\n",
       "      <td>193.149994</td>\n",
       "      <td>193.149994</td>\n",
       "      <td>48087700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-28 00:00:00-05:00</th>\n",
       "      <td>194.139999</td>\n",
       "      <td>194.660004</td>\n",
       "      <td>193.169998</td>\n",
       "      <td>193.580002</td>\n",
       "      <td>193.580002</td>\n",
       "      <td>34049900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-29 00:00:00-05:00</th>\n",
       "      <td>193.899994</td>\n",
       "      <td>194.399994</td>\n",
       "      <td>191.729996</td>\n",
       "      <td>192.529999</td>\n",
       "      <td>192.529999</td>\n",
       "      <td>42628800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Open        High         Low       Close  \\\n",
       "Date                                                                        \n",
       "2023-11-30 00:00:00-05:00  189.839996  190.320007  188.190002  189.949997   \n",
       "2023-12-01 00:00:00-05:00  190.330002  191.559998  189.229996  191.240005   \n",
       "2023-12-04 00:00:00-05:00  189.979996  190.050003  187.449997  189.429993   \n",
       "2023-12-05 00:00:00-05:00  190.210007  194.399994  190.179993  193.419998   \n",
       "2023-12-06 00:00:00-05:00  194.449997  194.759995  192.110001  192.320007   \n",
       "2023-12-07 00:00:00-05:00  193.630005  195.000000  193.589996  194.270004   \n",
       "2023-12-08 00:00:00-05:00  194.199997  195.990005  193.669998  195.710007   \n",
       "2023-12-11 00:00:00-05:00  193.110001  193.490005  191.419998  193.179993   \n",
       "2023-12-12 00:00:00-05:00  193.080002  194.720001  191.720001  194.710007   \n",
       "2023-12-13 00:00:00-05:00  195.089996  198.000000  194.850006  197.960007   \n",
       "2023-12-14 00:00:00-05:00  198.020004  199.619995  196.160004  198.110001   \n",
       "2023-12-15 00:00:00-05:00  197.529999  198.399994  197.000000  197.570007   \n",
       "2023-12-18 00:00:00-05:00  196.089996  196.630005  194.389999  195.889999   \n",
       "2023-12-19 00:00:00-05:00  196.160004  196.949997  195.889999  196.940002   \n",
       "2023-12-20 00:00:00-05:00  196.899994  197.679993  194.830002  194.830002   \n",
       "2023-12-21 00:00:00-05:00  196.100006  197.080002  193.500000  194.679993   \n",
       "2023-12-22 00:00:00-05:00  195.179993  195.410004  192.970001  193.600006   \n",
       "2023-12-26 00:00:00-05:00  193.610001  193.889999  192.830002  193.050003   \n",
       "2023-12-27 00:00:00-05:00  192.490005  193.500000  191.089996  193.149994   \n",
       "2023-12-28 00:00:00-05:00  194.139999  194.660004  193.169998  193.580002   \n",
       "2023-12-29 00:00:00-05:00  193.899994  194.399994  191.729996  192.529999   \n",
       "\n",
       "                            Adj Close     Volume  Dividends  Stock Splits  \n",
       "Date                                                                       \n",
       "2023-11-30 00:00:00-05:00  189.949997   48794400        0.0           0.0  \n",
       "2023-12-01 00:00:00-05:00  191.240005   45679300        0.0           0.0  \n",
       "2023-12-04 00:00:00-05:00  189.429993   43389500        0.0           0.0  \n",
       "2023-12-05 00:00:00-05:00  193.419998   66628400        0.0           0.0  \n",
       "2023-12-06 00:00:00-05:00  192.320007   41089700        0.0           0.0  \n",
       "2023-12-07 00:00:00-05:00  194.270004   47477700        0.0           0.0  \n",
       "2023-12-08 00:00:00-05:00  195.710007   53377300        0.0           0.0  \n",
       "2023-12-11 00:00:00-05:00  193.179993   60943700        0.0           0.0  \n",
       "2023-12-12 00:00:00-05:00  194.710007   52696900        0.0           0.0  \n",
       "2023-12-13 00:00:00-05:00  197.960007   70404200        0.0           0.0  \n",
       "2023-12-14 00:00:00-05:00  198.110001   66831600        0.0           0.0  \n",
       "2023-12-15 00:00:00-05:00  197.570007  128256700        0.0           0.0  \n",
       "2023-12-18 00:00:00-05:00  195.889999   55751900        0.0           0.0  \n",
       "2023-12-19 00:00:00-05:00  196.940002   40714100        0.0           0.0  \n",
       "2023-12-20 00:00:00-05:00  194.830002   52242800        0.0           0.0  \n",
       "2023-12-21 00:00:00-05:00  194.679993   46482500        0.0           0.0  \n",
       "2023-12-22 00:00:00-05:00  193.600006   37122800        0.0           0.0  \n",
       "2023-12-26 00:00:00-05:00  193.050003   28919300        0.0           0.0  \n",
       "2023-12-27 00:00:00-05:00  193.149994   48087700        0.0           0.0  \n",
       "2023-12-28 00:00:00-05:00  193.580002   34049900        0.0           0.0  \n",
       "2023-12-29 00:00:00-05:00  192.529999   42628800        0.0           0.0  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hist_unadj = apple.history(period=\"1mo\", auto_adjust=False)\n",
    "hist_unadj"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8b3a8fed-0499-4d5d-9dfe-4f0c484c0c56",
   "metadata": {},
   "source": [
    "### Including Dividends and Stock Splits\n",
    "To include dividend and stock split data, set actions to True:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "067abd0e-dce4-4fa5-8e72-2c4ac8490bfb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2018-12-31 00:00:00-05:00</th>\n",
       "      <td>38.039708</td>\n",
       "      <td>38.238870</td>\n",
       "      <td>37.547804</td>\n",
       "      <td>37.850147</td>\n",
       "      <td>140014000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-02 00:00:00-05:00</th>\n",
       "      <td>37.166273</td>\n",
       "      <td>38.116488</td>\n",
       "      <td>37.007904</td>\n",
       "      <td>37.893330</td>\n",
       "      <td>148158800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-03 00:00:00-05:00</th>\n",
       "      <td>34.548383</td>\n",
       "      <td>34.965902</td>\n",
       "      <td>34.073278</td>\n",
       "      <td>34.118870</td>\n",
       "      <td>365248800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-04 00:00:00-05:00</th>\n",
       "      <td>34.680375</td>\n",
       "      <td>35.644986</td>\n",
       "      <td>34.505210</td>\n",
       "      <td>35.575397</td>\n",
       "      <td>234428400</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2019-01-07 00:00:00-05:00</th>\n",
       "      <td>35.680973</td>\n",
       "      <td>35.712168</td>\n",
       "      <td>35.009104</td>\n",
       "      <td>35.496208</td>\n",
       "      <td>219111200</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-22 00:00:00-05:00</th>\n",
       "      <td>195.179993</td>\n",
       "      <td>195.410004</td>\n",
       "      <td>192.970001</td>\n",
       "      <td>193.600006</td>\n",
       "      <td>37122800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-26 00:00:00-05:00</th>\n",
       "      <td>193.610001</td>\n",
       "      <td>193.889999</td>\n",
       "      <td>192.830002</td>\n",
       "      <td>193.050003</td>\n",
       "      <td>28919300</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-27 00:00:00-05:00</th>\n",
       "      <td>192.490005</td>\n",
       "      <td>193.500000</td>\n",
       "      <td>191.089996</td>\n",
       "      <td>193.149994</td>\n",
       "      <td>48087700</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-28 00:00:00-05:00</th>\n",
       "      <td>194.139999</td>\n",
       "      <td>194.660004</td>\n",
       "      <td>193.169998</td>\n",
       "      <td>193.580002</td>\n",
       "      <td>34049900</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-29 00:00:00-05:00</th>\n",
       "      <td>193.899994</td>\n",
       "      <td>194.399994</td>\n",
       "      <td>191.729996</td>\n",
       "      <td>192.529999</td>\n",
       "      <td>42628800</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1259 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Open        High         Low       Close  \\\n",
       "Date                                                                        \n",
       "2018-12-31 00:00:00-05:00   38.039708   38.238870   37.547804   37.850147   \n",
       "2019-01-02 00:00:00-05:00   37.166273   38.116488   37.007904   37.893330   \n",
       "2019-01-03 00:00:00-05:00   34.548383   34.965902   34.073278   34.118870   \n",
       "2019-01-04 00:00:00-05:00   34.680375   35.644986   34.505210   35.575397   \n",
       "2019-01-07 00:00:00-05:00   35.680973   35.712168   35.009104   35.496208   \n",
       "...                               ...         ...         ...         ...   \n",
       "2023-12-22 00:00:00-05:00  195.179993  195.410004  192.970001  193.600006   \n",
       "2023-12-26 00:00:00-05:00  193.610001  193.889999  192.830002  193.050003   \n",
       "2023-12-27 00:00:00-05:00  192.490005  193.500000  191.089996  193.149994   \n",
       "2023-12-28 00:00:00-05:00  194.139999  194.660004  193.169998  193.580002   \n",
       "2023-12-29 00:00:00-05:00  193.899994  194.399994  191.729996  192.529999   \n",
       "\n",
       "                              Volume  Dividends  Stock Splits  \n",
       "Date                                                           \n",
       "2018-12-31 00:00:00-05:00  140014000        0.0           0.0  \n",
       "2019-01-02 00:00:00-05:00  148158800        0.0           0.0  \n",
       "2019-01-03 00:00:00-05:00  365248800        0.0           0.0  \n",
       "2019-01-04 00:00:00-05:00  234428400        0.0           0.0  \n",
       "2019-01-07 00:00:00-05:00  219111200        0.0           0.0  \n",
       "...                              ...        ...           ...  \n",
       "2023-12-22 00:00:00-05:00   37122800        0.0           0.0  \n",
       "2023-12-26 00:00:00-05:00   28919300        0.0           0.0  \n",
       "2023-12-27 00:00:00-05:00   48087700        0.0           0.0  \n",
       "2023-12-28 00:00:00-05:00   34049900        0.0           0.0  \n",
       "2023-12-29 00:00:00-05:00   42628800        0.0           0.0  \n",
       "\n",
       "[1259 rows x 7 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "hist_adj = apple.history(period=\"5y\", actions=True)\n",
    "hist_adj"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "06214d3b-20db-4676-a1a6-dfb7b0bd53e2",
   "metadata": {},
   "source": [
    "---\n",
    "## Advanced Usage\n",
    "\n",
    "### Fetching Data for Multiple Stocks\n",
    "\n",
    "To fetch data for multiple stocks, pass a list of ticker symbols to yf.download:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "62103fe6-bdb4-4906-bb92-eccdc9096dc2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[*********************100%%**********************]  3 of 3 completed\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe thead tr:last-of-type th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th colspan=\"3\" halign=\"left\">Adj Close</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Close</th>\n",
       "      <th colspan=\"3\" halign=\"left\">High</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Low</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Open</th>\n",
       "      <th colspan=\"3\" halign=\"left\">Volume</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th></th>\n",
       "      <th>AAPL</th>\n",
       "      <th>GOOG</th>\n",
       "      <th>MSFT</th>\n",
       "      <th>AAPL</th>\n",
       "      <th>GOOG</th>\n",
       "      <th>MSFT</th>\n",
       "      <th>AAPL</th>\n",
       "      <th>GOOG</th>\n",
       "      <th>MSFT</th>\n",
       "      <th>AAPL</th>\n",
       "      <th>GOOG</th>\n",
       "      <th>MSFT</th>\n",
       "      <th>AAPL</th>\n",
       "      <th>GOOG</th>\n",
       "      <th>MSFT</th>\n",
       "      <th>AAPL</th>\n",
       "      <th>GOOG</th>\n",
       "      <th>MSFT</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2020-01-02</th>\n",
       "      <td>73.152657</td>\n",
       "      <td>68.368500</td>\n",
       "      <td>154.779541</td>\n",
       "      <td>75.087502</td>\n",
       "      <td>68.368500</td>\n",
       "      <td>160.619995</td>\n",
       "      <td>75.150002</td>\n",
       "      <td>68.406998</td>\n",
       "      <td>160.729996</td>\n",
       "      <td>73.797501</td>\n",
       "      <td>67.077499</td>\n",
       "      <td>158.330002</td>\n",
       "      <td>74.059998</td>\n",
       "      <td>67.077499</td>\n",
       "      <td>158.779999</td>\n",
       "      <td>135480400</td>\n",
       "      <td>28132000</td>\n",
       "      <td>22622100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-03</th>\n",
       "      <td>72.441467</td>\n",
       "      <td>68.032997</td>\n",
       "      <td>152.852234</td>\n",
       "      <td>74.357498</td>\n",
       "      <td>68.032997</td>\n",
       "      <td>158.619995</td>\n",
       "      <td>75.144997</td>\n",
       "      <td>68.625000</td>\n",
       "      <td>159.949997</td>\n",
       "      <td>74.125000</td>\n",
       "      <td>67.277199</td>\n",
       "      <td>158.059998</td>\n",
       "      <td>74.287498</td>\n",
       "      <td>67.392998</td>\n",
       "      <td>158.320007</td>\n",
       "      <td>146322800</td>\n",
       "      <td>23728000</td>\n",
       "      <td>21116200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-06</th>\n",
       "      <td>73.018677</td>\n",
       "      <td>69.710503</td>\n",
       "      <td>153.247360</td>\n",
       "      <td>74.949997</td>\n",
       "      <td>69.710503</td>\n",
       "      <td>159.029999</td>\n",
       "      <td>74.989998</td>\n",
       "      <td>69.824997</td>\n",
       "      <td>159.100006</td>\n",
       "      <td>73.187500</td>\n",
       "      <td>67.500000</td>\n",
       "      <td>156.509995</td>\n",
       "      <td>73.447502</td>\n",
       "      <td>67.500000</td>\n",
       "      <td>157.080002</td>\n",
       "      <td>118387200</td>\n",
       "      <td>34646000</td>\n",
       "      <td>20813700</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-07</th>\n",
       "      <td>72.675270</td>\n",
       "      <td>69.667000</td>\n",
       "      <td>151.850052</td>\n",
       "      <td>74.597504</td>\n",
       "      <td>69.667000</td>\n",
       "      <td>157.580002</td>\n",
       "      <td>75.224998</td>\n",
       "      <td>70.149498</td>\n",
       "      <td>159.669998</td>\n",
       "      <td>74.370003</td>\n",
       "      <td>69.518997</td>\n",
       "      <td>157.320007</td>\n",
       "      <td>74.959999</td>\n",
       "      <td>69.897003</td>\n",
       "      <td>159.320007</td>\n",
       "      <td>108872000</td>\n",
       "      <td>30054000</td>\n",
       "      <td>21634100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-01-08</th>\n",
       "      <td>73.844345</td>\n",
       "      <td>70.216003</td>\n",
       "      <td>154.268814</td>\n",
       "      <td>75.797501</td>\n",
       "      <td>70.216003</td>\n",
       "      <td>160.089996</td>\n",
       "      <td>76.110001</td>\n",
       "      <td>70.579002</td>\n",
       "      <td>160.800003</td>\n",
       "      <td>74.290001</td>\n",
       "      <td>69.542000</td>\n",
       "      <td>157.949997</td>\n",
       "      <td>74.290001</td>\n",
       "      <td>69.603996</td>\n",
       "      <td>158.929993</td>\n",
       "      <td>132079200</td>\n",
       "      <td>30560000</td>\n",
       "      <td>27746500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-12-24</th>\n",
       "      <td>129.679718</td>\n",
       "      <td>86.942497</td>\n",
       "      <td>216.924301</td>\n",
       "      <td>131.970001</td>\n",
       "      <td>86.942497</td>\n",
       "      <td>222.750000</td>\n",
       "      <td>133.460007</td>\n",
       "      <td>87.300003</td>\n",
       "      <td>223.610001</td>\n",
       "      <td>131.100006</td>\n",
       "      <td>86.455498</td>\n",
       "      <td>221.199997</td>\n",
       "      <td>131.320007</td>\n",
       "      <td>86.750000</td>\n",
       "      <td>221.419998</td>\n",
       "      <td>54930100</td>\n",
       "      <td>6936000</td>\n",
       "      <td>10550600</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-12-28</th>\n",
       "      <td>134.317825</td>\n",
       "      <td>88.804497</td>\n",
       "      <td>219.076477</td>\n",
       "      <td>136.690002</td>\n",
       "      <td>88.804497</td>\n",
       "      <td>224.960007</td>\n",
       "      <td>137.339996</td>\n",
       "      <td>89.536400</td>\n",
       "      <td>226.029999</td>\n",
       "      <td>133.509995</td>\n",
       "      <td>87.316750</td>\n",
       "      <td>223.020004</td>\n",
       "      <td>133.990005</td>\n",
       "      <td>87.581749</td>\n",
       "      <td>224.449997</td>\n",
       "      <td>124486200</td>\n",
       "      <td>27860000</td>\n",
       "      <td>17933500</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-12-29</th>\n",
       "      <td>132.529388</td>\n",
       "      <td>87.935997</td>\n",
       "      <td>218.287643</td>\n",
       "      <td>134.869995</td>\n",
       "      <td>87.935997</td>\n",
       "      <td>224.149994</td>\n",
       "      <td>138.789993</td>\n",
       "      <td>89.622002</td>\n",
       "      <td>227.179993</td>\n",
       "      <td>134.339996</td>\n",
       "      <td>87.804497</td>\n",
       "      <td>223.580002</td>\n",
       "      <td>138.050003</td>\n",
       "      <td>89.389503</td>\n",
       "      <td>226.309998</td>\n",
       "      <td>121047300</td>\n",
       "      <td>25988000</td>\n",
       "      <td>17403200</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-12-30</th>\n",
       "      <td>131.399368</td>\n",
       "      <td>86.975998</td>\n",
       "      <td>215.882233</td>\n",
       "      <td>133.720001</td>\n",
       "      <td>86.975998</td>\n",
       "      <td>221.679993</td>\n",
       "      <td>135.990005</td>\n",
       "      <td>88.254753</td>\n",
       "      <td>225.630005</td>\n",
       "      <td>133.399994</td>\n",
       "      <td>86.279999</td>\n",
       "      <td>221.470001</td>\n",
       "      <td>135.580002</td>\n",
       "      <td>88.100502</td>\n",
       "      <td>225.229996</td>\n",
       "      <td>96452100</td>\n",
       "      <td>26122000</td>\n",
       "      <td>20272300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2020-12-31</th>\n",
       "      <td>130.387238</td>\n",
       "      <td>87.594002</td>\n",
       "      <td>216.602905</td>\n",
       "      <td>132.690002</td>\n",
       "      <td>87.594002</td>\n",
       "      <td>222.419998</td>\n",
       "      <td>134.740005</td>\n",
       "      <td>87.946503</td>\n",
       "      <td>223.000000</td>\n",
       "      <td>131.720001</td>\n",
       "      <td>86.771004</td>\n",
       "      <td>219.679993</td>\n",
       "      <td>134.080002</td>\n",
       "      <td>86.771004</td>\n",
       "      <td>221.699997</td>\n",
       "      <td>99116600</td>\n",
       "      <td>20238000</td>\n",
       "      <td>20942100</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>253 rows × 18 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             Adj Close                              Close             \\\n",
       "                  AAPL       GOOG        MSFT        AAPL       GOOG   \n",
       "Date                                                                   \n",
       "2020-01-02   73.152657  68.368500  154.779541   75.087502  68.368500   \n",
       "2020-01-03   72.441467  68.032997  152.852234   74.357498  68.032997   \n",
       "2020-01-06   73.018677  69.710503  153.247360   74.949997  69.710503   \n",
       "2020-01-07   72.675270  69.667000  151.850052   74.597504  69.667000   \n",
       "2020-01-08   73.844345  70.216003  154.268814   75.797501  70.216003   \n",
       "...                ...        ...         ...         ...        ...   \n",
       "2020-12-24  129.679718  86.942497  216.924301  131.970001  86.942497   \n",
       "2020-12-28  134.317825  88.804497  219.076477  136.690002  88.804497   \n",
       "2020-12-29  132.529388  87.935997  218.287643  134.869995  87.935997   \n",
       "2020-12-30  131.399368  86.975998  215.882233  133.720001  86.975998   \n",
       "2020-12-31  130.387238  87.594002  216.602905  132.690002  87.594002   \n",
       "\n",
       "                              High                                Low  \\\n",
       "                  MSFT        AAPL       GOOG        MSFT        AAPL   \n",
       "Date                                                                    \n",
       "2020-01-02  160.619995   75.150002  68.406998  160.729996   73.797501   \n",
       "2020-01-03  158.619995   75.144997  68.625000  159.949997   74.125000   \n",
       "2020-01-06  159.029999   74.989998  69.824997  159.100006   73.187500   \n",
       "2020-01-07  157.580002   75.224998  70.149498  159.669998   74.370003   \n",
       "2020-01-08  160.089996   76.110001  70.579002  160.800003   74.290001   \n",
       "...                ...         ...        ...         ...         ...   \n",
       "2020-12-24  222.750000  133.460007  87.300003  223.610001  131.100006   \n",
       "2020-12-28  224.960007  137.339996  89.536400  226.029999  133.509995   \n",
       "2020-12-29  224.149994  138.789993  89.622002  227.179993  134.339996   \n",
       "2020-12-30  221.679993  135.990005  88.254753  225.630005  133.399994   \n",
       "2020-12-31  222.419998  134.740005  87.946503  223.000000  131.720001   \n",
       "\n",
       "                                         Open                         \\\n",
       "                 GOOG        MSFT        AAPL       GOOG        MSFT   \n",
       "Date                                                                   \n",
       "2020-01-02  67.077499  158.330002   74.059998  67.077499  158.779999   \n",
       "2020-01-03  67.277199  158.059998   74.287498  67.392998  158.320007   \n",
       "2020-01-06  67.500000  156.509995   73.447502  67.500000  157.080002   \n",
       "2020-01-07  69.518997  157.320007   74.959999  69.897003  159.320007   \n",
       "2020-01-08  69.542000  157.949997   74.290001  69.603996  158.929993   \n",
       "...               ...         ...         ...        ...         ...   \n",
       "2020-12-24  86.455498  221.199997  131.320007  86.750000  221.419998   \n",
       "2020-12-28  87.316750  223.020004  133.990005  87.581749  224.449997   \n",
       "2020-12-29  87.804497  223.580002  138.050003  89.389503  226.309998   \n",
       "2020-12-30  86.279999  221.470001  135.580002  88.100502  225.229996   \n",
       "2020-12-31  86.771004  219.679993  134.080002  86.771004  221.699997   \n",
       "\n",
       "               Volume                      \n",
       "                 AAPL      GOOG      MSFT  \n",
       "Date                                       \n",
       "2020-01-02  135480400  28132000  22622100  \n",
       "2020-01-03  146322800  23728000  21116200  \n",
       "2020-01-06  118387200  34646000  20813700  \n",
       "2020-01-07  108872000  30054000  21634100  \n",
       "2020-01-08  132079200  30560000  27746500  \n",
       "...               ...       ...       ...  \n",
       "2020-12-24   54930100   6936000  10550600  \n",
       "2020-12-28  124486200  27860000  17933500  \n",
       "2020-12-29  121047300  25988000  17403200  \n",
       "2020-12-30   96452100  26122000  20272300  \n",
       "2020-12-31   99116600  20238000  20942100  \n",
       "\n",
       "[253 rows x 18 columns]"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = yf.download(\"AAPL MSFT GOOG\", start=\"2020-01-01\", end=\"2021-01-01\")\n",
    "data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d6d16c7e-66ca-4f73-be90-5721d5289250",
   "metadata": {},
   "source": [
    "### Fetching Real-Time Data\n",
    "For real-time data, you can use the interval parameter with the history method. For example, fetching minute-level data for the past 5 days:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "06aa87a7-b678-4b28-8ee7-3042bade22e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Open</th>\n",
       "      <th>High</th>\n",
       "      <th>Low</th>\n",
       "      <th>Close</th>\n",
       "      <th>Volume</th>\n",
       "      <th>Dividends</th>\n",
       "      <th>Stock Splits</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2023-12-22 09:30:00-05:00</th>\n",
       "      <td>195.179993</td>\n",
       "      <td>195.410004</td>\n",
       "      <td>195.054993</td>\n",
       "      <td>195.389999</td>\n",
       "      <td>1303572</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-22 09:31:00-05:00</th>\n",
       "      <td>195.380005</td>\n",
       "      <td>195.399994</td>\n",
       "      <td>195.057007</td>\n",
       "      <td>195.080002</td>\n",
       "      <td>180031</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-22 09:32:00-05:00</th>\n",
       "      <td>195.080002</td>\n",
       "      <td>195.139999</td>\n",
       "      <td>194.990005</td>\n",
       "      <td>195.050003</td>\n",
       "      <td>170886</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-22 09:33:00-05:00</th>\n",
       "      <td>195.050003</td>\n",
       "      <td>195.110001</td>\n",
       "      <td>194.880005</td>\n",
       "      <td>194.910004</td>\n",
       "      <td>159125</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-22 09:34:00-05:00</th>\n",
       "      <td>194.919998</td>\n",
       "      <td>194.945007</td>\n",
       "      <td>194.710007</td>\n",
       "      <td>194.720001</td>\n",
       "      <td>153678</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-29 15:55:00-05:00</th>\n",
       "      <td>192.350006</td>\n",
       "      <td>192.460007</td>\n",
       "      <td>192.160004</td>\n",
       "      <td>192.315002</td>\n",
       "      <td>456133</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-29 15:56:00-05:00</th>\n",
       "      <td>192.320007</td>\n",
       "      <td>192.550003</td>\n",
       "      <td>192.250000</td>\n",
       "      <td>192.544998</td>\n",
       "      <td>290777</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-29 15:57:00-05:00</th>\n",
       "      <td>192.535004</td>\n",
       "      <td>192.570007</td>\n",
       "      <td>192.440002</td>\n",
       "      <td>192.490005</td>\n",
       "      <td>314258</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-29 15:58:00-05:00</th>\n",
       "      <td>192.485001</td>\n",
       "      <td>192.570007</td>\n",
       "      <td>192.479996</td>\n",
       "      <td>192.520004</td>\n",
       "      <td>466848</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2023-12-29 15:59:00-05:00</th>\n",
       "      <td>192.520004</td>\n",
       "      <td>192.899994</td>\n",
       "      <td>192.479996</td>\n",
       "      <td>192.520004</td>\n",
       "      <td>2202006</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>1950 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                 Open        High         Low       Close  \\\n",
       "Datetime                                                                    \n",
       "2023-12-22 09:30:00-05:00  195.179993  195.410004  195.054993  195.389999   \n",
       "2023-12-22 09:31:00-05:00  195.380005  195.399994  195.057007  195.080002   \n",
       "2023-12-22 09:32:00-05:00  195.080002  195.139999  194.990005  195.050003   \n",
       "2023-12-22 09:33:00-05:00  195.050003  195.110001  194.880005  194.910004   \n",
       "2023-12-22 09:34:00-05:00  194.919998  194.945007  194.710007  194.720001   \n",
       "...                               ...         ...         ...         ...   \n",
       "2023-12-29 15:55:00-05:00  192.350006  192.460007  192.160004  192.315002   \n",
       "2023-12-29 15:56:00-05:00  192.320007  192.550003  192.250000  192.544998   \n",
       "2023-12-29 15:57:00-05:00  192.535004  192.570007  192.440002  192.490005   \n",
       "2023-12-29 15:58:00-05:00  192.485001  192.570007  192.479996  192.520004   \n",
       "2023-12-29 15:59:00-05:00  192.520004  192.899994  192.479996  192.520004   \n",
       "\n",
       "                            Volume  Dividends  Stock Splits  \n",
       "Datetime                                                     \n",
       "2023-12-22 09:30:00-05:00  1303572        0.0           0.0  \n",
       "2023-12-22 09:31:00-05:00   180031        0.0           0.0  \n",
       "2023-12-22 09:32:00-05:00   170886        0.0           0.0  \n",
       "2023-12-22 09:33:00-05:00   159125        0.0           0.0  \n",
       "2023-12-22 09:34:00-05:00   153678        0.0           0.0  \n",
       "...                            ...        ...           ...  \n",
       "2023-12-29 15:55:00-05:00   456133        0.0           0.0  \n",
       "2023-12-29 15:56:00-05:00   290777        0.0           0.0  \n",
       "2023-12-29 15:57:00-05:00   314258        0.0           0.0  \n",
       "2023-12-29 15:58:00-05:00   466848        0.0           0.0  \n",
       "2023-12-29 15:59:00-05:00  2202006        0.0           0.0  \n",
       "\n",
       "[1950 rows x 7 columns]"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "real_time_data = apple.history(period=\"5d\", interval=\"1m\")\n",
    "real_time_data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cb913f30-916b-48ca-a7c1-95609b47d817",
   "metadata": {},
   "source": [
    "**Note:**\n",
    "* Real-time data might be delayed by up to 15 minutes due to Yahoo Finance’s limitations."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bec1a5bd-83f2-4f4f-92be-a731fbd74a98",
   "metadata": {},
   "source": [
    "---\n",
    "## Conclusion\n",
    "yfinance is a powerful tool that provides easy access to a wealth of financial data. By integrating yfinance into your analysis, you gain the ability to make more informed decisions based on historical and real-time market data. Happy data hunting."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
